package ui;

import bayes.BayesSwing;
import engine.AbstractVectorTI.VectorType;
import engine.Stats;
import engine.Tweet.Polarity;
import java.io.IOException;
import normalisation.Normalizer;
import normalisation.Normalizer.EncodageType;
import normalisation.Normalizer.NormalisationType;

public class AppliConsole {

    private static final String OPTION_UI = "-g";
//    private static final String OPTION_STAT = "-s";
//    private static final String OPTION_TRAIN = "-t";
    private static final String PATH_SWENGLISH = "englishST.txt";

    private static Normalizer makeNormaliser(NormalisationType normType, boolean bAccent, boolean bPonctuation,
            boolean bNombre, boolean bSW, boolean bOneOccur, boolean bRemTag, String urlReplace) {

        EncodageType encodageType = EncodageType.UTF_8;
        return new Normalizer(normType, encodageType, bAccent, bPonctuation, bNombre, bSW,
                PATH_SWENGLISH, bOneOccur, bRemTag, !urlReplace.isEmpty(), urlReplace);
    }

    private static Double[] getCoeffsAntiPenality() {
        Double[] coeffsAntiPenality = new Double[Polarity.values().length];
        coeffsAntiPenality[Polarity.positive.ordinal()] = 1.40;
        coeffsAntiPenality[Polarity.negative.ordinal()] = 1.20;
        coeffsAntiPenality[Polarity.neutral.ordinal()] = 1.00;
        coeffsAntiPenality[Polarity.irrelevant.ordinal()] = 1.00;
        coeffsAntiPenality[Polarity.unknown.ordinal()] = 2.05;

        return coeffsAntiPenality;
    }

    public static void main(String args[]) throws IOException {

        /*Test des arguments données au programme*/
        if (args.length == 0 || args[0].equals(OPTION_UI)) {

            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>

            /* Create and display the form */
            java.awt.EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new UserInterface().setVisible(true);
                }
            });
        } else if (args.length > 0 ) {
            String trainFilePath = args[0]; //"train.txt";
            String testFilePath = args[1]; //"test.txt";

            Normalizer normalizer = makeNormaliser(NormalisationType.Tokenisation, true, true, true, true, true, true, "urlReplaced");
            Stats stats = new Stats(trainFilePath, normalizer, VectorType.None);
            stats.makeStats();

            BayesSwing bayes = new BayesSwing(null,
                    testFilePath,
                    trainFilePath,
                    normalizer,
                    getCoeffsAntiPenality(),
                    null,
                    true);//true = binomial

            bayes.executeBayes();
        }
    }
}
